library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tayloRswift)
library(tidytuesdayR)
library(ggplot2)
library(dplyr)
library(ggthemes)
library(maps)
## 
## Attaching package: 'maps'
## 
## The following object is masked from 'package:purrr':
## 
##     map
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(cartography)
## This project is in maintenance mode. 
## Core functionalities of `cartography` can be found in `mapsf`.
## https://riatelab.github.io/mapsf/
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
shapenames <- read_sf( "CA_Counties", "CA_Counties_TIGER2016")
jail_America <- readr::read_csv("./Allstatesinsurvey/all_jails.csv")
## Rows: 523 Columns: 116
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): statecode, state, state_notes, county, jail, jail_notes, med2008, ...
## dbl (98): id, fips, d2008, d2009, d2010, d2011, d2012, d2013, d2014, d2015, ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
jail_deaths_in_Americas <- readr::read_csv("./Allstatesinsurvey/all_deaths.csv")
## Rows: 7571 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): state, county, jail, date_of_death, full_name, last_name, first_na...
## dbl  (4): id, year, yob, age
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#irports_Jordan %>%
  #leaflet() %>% 
  #addTiles() %>% 
  #addMarkers(lng = ~longitude, lat = ~latitude, label = ~description)
#calif

California_deaths <-jail_deaths_in_Americas %>% 
filter(state=="CA")%>%
group_by(county)%>%
summarize( total_deaths=n()) #counts how many rows inside that group


prisondeath<-shapenames %>% 
  left_join( California_deaths, by=c( "NAME"= "county"))
   
  map <-  ggplot(data= prisondeath, aes(fill= total_deaths)) + 
    geom_sf(fill="white")+
    labs(x="Latitude of California", y="Lonigitude of California")+
    geom_sf_text(mapping = aes(label= NAME), size=1)+
      theme(legend.position = "none")

ggplotly(map)